package com.hjc.springbootmovies.controller;

import com.hjc.springbootmovies.entity.ModelEmp;
import com.hjc.springbootmovies.service.Impl.EmpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by IntelliJ IDEA.
 * User: HJC
 * Date: 2019/12/4
 * Time: 14:34
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("emp")
public class EmpController {
    @Autowired
    private EmpServiceImpl empService;

    @GetMapping("empControllerAll")
    public String empAll(){
        return "html/emp/all";
    }

    @GetMapping("empControllerAdd")
    public String empAdd(){
        return "html/emp/add";
    }

    @GetMapping("empControllerUpdate")
    public String empUpdate(int eid ,Model model){
        model.addAttribute("update" , empService.queryById(eid) );
        return "html/emp/update";
    }

    @RequestMapping(value = "addEmp" ,method = RequestMethod.POST)
    public String addEmp(ModelEmp modelEmp){
        int count = empService.addEmp(modelEmp);
        return"html/emp/all";
    }

    @RequestMapping(value = "deleteById" ,method = RequestMethod.GET)
    public String deleteById(int eid){
        int count = empService.deleteById(eid);
        return"html/emp/all";
    }

    @RequestMapping(value = "updateEmp" ,method = RequestMethod.POST)
    public String updateEmp(ModelEmp modelEmp){
        int count = empService.updateEmp(modelEmp);
        return"html/emp/all";
    }
}
